﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
function checkValue(postdata, formid) {
	var qualify = postdata.qualify;
	if (qualify.length > 30) {
		return [false,"所输入服务商资质的长度不能超过30"];
	}
	return [true,""];
};

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=13',
			datatype: "json",
			hidegrid: "false",
			colNames:['公司编码','公司名称','服务资质','所属区'], 
			colModel:[
					{name:'id', width:100,align:'right',sortable:false,editable:true,editoptions:{size:6,maxlength:4},editrules:{required:true,number:true}}, 
					{name:'comname', width:220,align:'right', sortable:false,editable:true,editoptions:{size:20,maxlength:20},editrules:{required:true}},
					{name:'qualify', width:480,align:'right', sortable:false,editable:true,edittype:"textarea",editoptions:{rows:"2",cols:"18"},editrules:{required:true}},
					{name:'district',width:120,align:'right', sortable:false, editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:桥西区;2:桥东区;3:新华区;4:裕华区;5:长安区;6:高新区"}}
			], 
			viewrecords: true,
			rowNum:200,
			pager: '#gridpager1',
			editurl:'main?action=13',
			caption:"服务商管理",
			subGrid: true,
			height: 460,
			subGridRowExpanded: function(subgrid_id, row_id) {
				var subgrid_table_id, pager_id;
				subgrid_table_id = subgrid_id+"_t";
				subgridid = subgrid_table_id;
				pager_id = "p_"+subgrid_table_id;
				
				$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
				jQuery("#"+subgrid_table_id).jqGrid({
					url:"main?action=2&comid="+row_id,
					datatype: "json",
					colNames:['手机IMEI','姓名','手机号码','身份证号','公司ID','公司名称','状态'], 
					colModel:[ 
							{name:'imei', width:120, sortable:false, align:'right',hidden:true}, 
							{name:'wname',width:150, sortable:false, align:'right'}, 
							{name:'mobile',width:200, sortable:false, align:'right'},
							{name:'idcard', width:200, sortable:false, align:'right'},
							{name:'comid', width:160, sortable:false, align:'right',hidden:true},
							{name:'company', width:160, sortable:false, align:'right',hidden:true},
							{name:'state',width:110, sortable:false, align:'right', formatter:'select', editoptions:{value:"0:待确认;1:正常;2:停止工作"}}
					], 
					viewrecords: true,
					rowNum: 100,
					pager: pager_id, 
					height: '100%'
				});
			},
			subGridRowColapsed: function(subgrid_id, row_id) {
				// this function is called before removing the data
				var subgrid_table_id;
				subgrid_table_id = subgrid_id+"_t";
				jQuery("#"+subgrid_table_id).remove();
			}
  })
}; 
	
	$(document).ready(function(){
		setGrid();
		jQuery("#list1").jqGrid('navGrid','#gridpager1',{edit:false,add:false,del:false,refresh:false,search:false})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"添加", 
   		buttonicon:"ui-icon-plus", 
   		onClickButton: function(){
				jQuery("#list1").jqGrid('editGridRow','new',{
					addCaption:"添加一个服务商",
					bSubmit:"保存",bCancel:"取消",modal: true, 
					closeAfterAdd:true, 
					reloadAfterSubmit:true,
					beforeSubmit:checkValue,
					beforeShowForm:function(formid) {
						$('#comid').attr("readonly",false);
					},
					afterSubmit : function(r, postdata) {
			  					var data = eval('(' + r.responseText + ')');
			  					switch (data.code) {
			  						case 0: return [true, data.message];
			  						case 30000: return [false, "添加失败，编码不能重复！"];
			  						default: return [false, data.message];
			  					}
			  	}
				}); 
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"更改", 
   		buttonicon:"ui-icon-wrench", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null )
				  jQuery("#list1").jqGrid('editGridRow',gr,{
				  	editCaption:"更改服务商信息",
				  	bSubmit:"保存",bCancel:"取消",modal: true,
				  	closeAfterEdit:true,
				  	viewPagerButtons:false, 
				  	reloadAfterSubmit:true,
				  	beforeSubmit:checkValue,
				  	beforeShowForm:function(formid) {
				  		$('#comid').attr("readonly",true);
				  	},
				  	afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					if (data.code != 0)
				  						return [false, data.message];
				  					else
				  						return [true, data.message];
				  	}
				  });
				else
					showTips("请选择要更改的服务商");
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"删除", 
   		buttonicon:"ui-icon-close", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null ) {
					var cv = jQuery("#list1").jqGrid('getCell', gr, 1);
				  jQuery("#list1").jqGrid('delGridRow', gr, {
				  	caption:"确定要删除服务商?", 
				  	msg:"确定要删除这个服务商'" + cv + "'？",
				  	bSubmit:"删除",bCancel:"取消",modal: true,
				  	closeAfterEdit:true, 
				  	reloadAfterSubmit:true,
				  	afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					if (data.code != 0)
				  						return [false, data.message];
				  					else
				  						return [true, data.message];
				  	}
				  });
				} else
					showTips("请选择要删除的服务商");
			}
		});
	});
</script>

<body style="background-color:#4e84c0;">

				<div id="RightPane">
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager1"></div>
				</div>
</body>
